{% extends "base.html" %}
{% load crispy_forms_tags %}

{% block content %}
  <article class="media content-section">
    <!-- <img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}"> -->
    <div class="media-body">
      <div class="article-metadata">
        <a class="mr-2" href="#">{{ post.author }}</a>
        <small class="text-muted">{{ post.date_posted }}</small>
        <!-- <small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small> -->
      </div>
      <h4 class="article-title">{{ post.question }}</h2>
        <p class="article-content">{{ post.content }}</p>
        <div>
          <a class="btn btn-sm btn-info" href="{% url 'home' %}">查看其他问题</a>
          {% if post.author == user %}
          <a class="btn btn-success btn-sm mt-1 mb-1" href="{% url 'update' post.id %}">更新</a>
          <a class="btn btn-danger btn-sm mt-1 mb-1" href="{% url 'delete' post.id %}">删除</a>
          {% endif %}
        </div>
    </div>
  </article>

  {% for answer in answers %}
  <article class="media content-section">
    <!-- <img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}"> -->
    <div class="media-body">
      <div class="article-metadata">
        <small class="text-muted"><a href="#">{{ answer.author }}</a> 于 {{ answer.date_answered }} 回答。</small>
        <!-- <small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small> -->
      </div>
      <p class="article-content">{{ answer.context }}</p>


    </div>
  </article>
  {% endfor %}

  {% for answer in mrc_answers %}
  <article class="media content-section">
    <!-- <img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}"> -->
    <div class="media-body">
      <div class="article-metadata">
        <small class="text-muted"><a href="#">机器阅读理解模型</a> 于 {{ answer.date_answered }} 回答。</small>
      </div>
      <p class="article-content">{{ answer.context | safe }}</p>

    </div>
  </article>
  {% endfor %}


  <div class="content-section">
    <legend>添加新的答案</legend>
    {% if user.is_authenticated %}
    <form method="POST">
      {% csrf_token %}
      <fieldset class="form-group">
        <!-- {{ answer_form|crispy }} -->
        {{ form|crispy }}
      </fieldset>
      <div class="form-group">
        <button class="btn btn-sm btn-outline-info" type="submit">回复</button>
      </div>
    </form>
    {% else %}
    <p><a href="{% url 'login' %}?next={{ request.path }}">登录</a>账号即可进行回答。</p>
    {% endif %}

  </div>

{% endblock %}